//
//  InquiryRecordViewController.m
//  Runone
//
//  Created by runone02 on 16/11/21.
//  Copyright © 2016年 runone. All rights reserved.
//

#import "InquiryRecordViewController.h"
//#import "HistoryRecordCell.h"
#import "AppDelegate.h"
#import "RequestHelper.h"
#import "RequestGinsengModel.h"
#import "HistoryRecordModel.h"
#import "IntVclUserInfoModel.h"
#import "MJExtension.h"
#import "InquiryRecordCell.h"
#import "CarManagerHistoryViewController.h"
@interface InquiryRecordViewController ()

@property (nonatomic, strong) NSArray *dataArray;
@property (nonatomic, strong) HistoryRecordModel *recorModel;
@end

@implementation InquiryRecordViewController

#pragma   -------- 历史记录按钮点击

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configNaviBar];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"InquiryRecordCell" bundle:nil] forCellReuseIdentifier:@"HistoryCell"];
    self.automaticallyAdjustsScrollViewInsets  = NO;
    self.tableView.contentInset                = UIEdgeInsetsMake(64, 0, 0, 0);
    self.tableView.separatorStyle              = UITableViewCellSeparatorStyleNone;
//    self.tableView.estimatedRowHeight          = 120;
//     self.tableView.rowHeight                  = UITableViewAutomaticDimension;
    _recorModel = [[HistoryRecordModel alloc] init];
    [self requestData];
}

//设置标题
- (void) configNaviBar {
    UILabel *label                = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 30)];
    label.text                    = @"查询记录";
    label.textAlignment           = NSTextAlignmentCenter;
    label.textColor               = [UIColor whiteColor];
    self.navigationItem.titleView = label;
}

- (void) requestData {
    RequestHelper *requestHelper                  = [[RequestHelper alloc] init];
    RequestGinsengModel *GetAllLastestVehicleDynamicModel = [[RequestGinsengModel alloc] init];
    GetAllLastestVehicleDynamicModel.URL                  = GetAllLastestVehicleDynamicURL;
    GetAllLastestVehicleDynamicModel.DataValue            = [self dataValueWithVehicleNO:_vehicleNO RecordUID:@"" PageSize:@"10"];
    GetAllLastestVehicleDynamicModel.UpdatedTime          = @"";
    GetAllLastestVehicleDynamicModel.SystemCode           = @"GuangleHighway";
    GetAllLastestVehicleDynamicModel.MethodName           = @"SearchIntVclDrivedRecordInfoList";
    requestHelper.block=^(RequestOutginseng *requestOutginseng,id dataValueModel) {
//        NSLog(@"%@",requestOutginseng.DataValue);
        _dataArray = [HistoryRecordModel mj_objectArrayWithKeyValuesArray:requestOutginseng.DataValue];
        [self.tableView reloadData];
    };
    [requestHelper RequestGinsengModel:GetAllLastestVehicleDynamicModel andPushController:self];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    InquiryRecordCell *Cell      = [tableView dequeueReusableCellWithIdentifier:@"HistoryCell" forIndexPath:indexPath];
    Cell.recordModel             = _dataArray[indexPath.row];
    return Cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    HistoryRecordModel *model = _dataArray[indexPath.row];
    return model.currentCellH;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//    HistoryRecordModel *modelT=[[HistoryRecordModel alloc] init];
    CarManagerHistoryViewController *vc=[[CarManagerHistoryViewController alloc] init];
    vc.arr=_dataArray;
    
    
}

- (NSString *)dataValueWithVehicleNO:(NSString *)VehicleNO RecordUID:(NSString *)RecordUID PageSize:(NSString *)size {
    NSString *valueStr = [NSString stringWithFormat:@"[{\"key\":\"VehicleNo\",\"value\":\"%@\"},{\"key\":\"RecordUID\",\"value\":\"%@\"},{\"key\":\"PageSize\",\"value\":\"%@\"}]", VehicleNO, RecordUID, size];
    return valueStr;
}
@end
